<template>
  <div style="color: #666">
    <div style="border-bottom: 1px solid black;font-size: 20px;padding:10px 0 10px 50px">留言栏</div>
    <div style="margin: 10px 0 0 40px;">
      <el-input style="width: 300px" placeholder="搜索留言标题" suffix-icon="el-icon-search" v-model="name"
                size="small"></el-input>
      <el-button class="ml-5" type="primary" @click="load" size="small">搜索</el-button>
      <el-button type="warning" @click="reset" size="small">重置</el-button>
    </div>
    <div style="margin: 10px 0">
      <div style="padding: 10px 0 10px 60px;border-bottom: 1px dashed #ccc;" v-for="item in tableData" :key="item.id" >
        <div class="pd-10" style="font-size: 20px;color: #3F5EFB;cursor: pointer" @click="$router.push('/messageDetail?id='+item.id)">{{item.message.slice(0,4)+'......'}}</div>
        <div style="font-size: 14px;margin-top: 10px;">
          <i class="el-icon-user-solid"></i><span>{{item.createUser}}</span>
          <i class="el-icon-time" style="margin-left: 20px"></i><span>{{item.createTime}}</span>
        </div>
      </div>
    </div>
    <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[2, 5, 10, 20]"
          :page-size="pageSize"
          layout="total, prev, next, sizes , pager,  jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "MessageList",
  data() {
    return {
      tableData: [],
      name: '',
      pageNum: 1,
      pageSize: 5,
      total: 0,
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
    }
  },
  created() {
    this.load()
  },
  methods: {
    // 加载数据库中所有留言记录
    load() {
      this.request.get("/message/page", {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          // name: this.name,
        }
      }).then(res => {
        this.tableData = res.data.records
        console.log(this.tableData[0].createTime)
        this.total = res.data.total
      })
    },
    // 重置
    reset() {
      this.name = ""
      this.load()
    },
    // 操作页码
    handleSizeChange(pageSize) {
      this.pageSize = pageSize
      this.load()
    },
    // 调整单页面条数
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum
      this.load()
    },
  }
}
</script>

<style scoped>

</style>
